package gc3d.griddata;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Serializable;

/**
 * @author Pierrick
 *
 */
public class SimpleFile implements Serializable {
	private static final long serialVersionUID = 1L;
	private String name;
	private byte[] data;

	public SimpleFile(String path, String name) throws IOException {
		this.name = name;
		File file = new File(path 
				+ File.separatorChar + name);
		this.data = new byte[(int) file.length()];
		// (2^31)/(8*(1024^2)) = 256 MB max. OK for PNG
		FileInputStream fis = new FileInputStream(file);
		fis.read(data);
		fis.close();
	}

	public void write(String path) throws IOException {
		FileOutputStream fos = new FileOutputStream(path 
				+ File.separatorChar + name);
		fos.write(data);
		fos.close();
	}
}
